from typing import List
class Solution:
    #方法一：先排序再给出第k大的数
    def findKthLargest1(self, k: int,nums: List[int]= None) -> int:
        if not nums:
            nums = [6,1,2,3,4,5]
            a = sorted(nums)[k]
        return a
    #方法二：通过比较前k位数来筛选第k大的数
    def findKthLargest2(self, k: int,nums: List[int]= None) -> int:
        b = []
        if not nums:
            nums = [6,1,2,3,4,5]
            for i in nums:
                inserted = False
                for j in range(len(b)):
                    if i>b[j]:
                        b.insert(j,i)
                        inserted = True
                        break
                if not inserted:
                    b.append(i)
                if(len(b)>k):
                    b.pop()
        return b[-1]
if __name__ == '__main__':
    s = Solution()
    print(s.findKthLargest1(3))
    print(s.findKthLargest2(3))
